home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 23 / AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso / Updates / Librarys / MMULib / C_Sources / MuFastChip.c < prev    next >
C/C++ Source or Header  |  1999-11-28  |  14KB  |  367 lines

  1. /*****************************************************************
  2.  ** MuFastChip                                                  **
  3.  **                                                             **
  4.  ** Enable imprecise/nonserial flags for Chip memory            **
  5.  ** Release 40.2, © 1999 THOR-Software inc.                     **
  6.  ** 28.11.1999 Thomas Richter                                   **
  7.  *****************************************************************/
  8.  
  9. /// Includes
  10. #include <exec/types.h>
  11. #include <exec/memory.h>
  12. #include <exec/ports.h>
  13. #include <exec/execbase.h>
  14. #include <dos/dos.h>
  15. #include <mmu/mmubase.h>
  16. #include <mmu/context.h>
  17. #include <mmu/mmutags.h>
  18. #include <workbench/startup.h>
  19.  
  20. #include <thor/conversions.h>
  21.  
  22. #include <proto/exec.h>
  23. #include <proto/mmu.h>
  24. #include <proto/dos.h>
  25. #include <proto/icon.h>
  26. #include <string.h>
  27. ///
  28. /// Defines
  29. #define STRINGDATE "28.11.99"
  30. #define STRINGVERSION "40.2"
  31. #define TEMPLATE "ON/S,OFF/S"
  32.  
  33. #define OPT_ON 0
  34. #define OPT_OFF 1
  35. #define OPT_WINDOW 2
  36. #define OPT_COUNT 3
  37. ///
  38. /// Statics
  39. struct MMUBase *MMUBase;
  40. struct DosLibrary *DOSBase;
  41. struct ExecBase *SysBase;
  42. struct Library *IconBase;
  43. ///
  44. /// Protos
  45. int __asm __saveds main(void);
  46. int SetCacheMode(ULONG from,ULONG size,ULONG flags,ULONG mask);
  47. struct RDArgs *ReadTTArgs(struct WBStartup *msg,LONG args[],struct RDArgs **tmp);
  48. int DisableFastChip(void);
  49. int EnableFastChip(void);
  50. BOOL FindChipLimits(ULONG *from,ULONG *size);
  51. ///
  52.  
  53. char version[]="$VER: MuFastChip " STRINGVERSION " (" STRINGDATE ") © THOR";
  54.  
  55. /// main
  56. int __asm __saveds main(void)
  57. {
  58. LONG args[OPT_COUNT];
  59. struct RDArgs *rd,*myrd;
  60. struct Process *proc;
  61. int rc=20;
  62. LONG err;
  63. struct WBStartup *msg;
  64. BPTR oldout;
  65. struct MsgPort *oldconsole;
  66.  
  67.         SysBase=*((struct ExecBase **)(4L));
  68.  
  69.         memset(args,0,sizeof(LONG)*OPT_COUNT);
  70.  
  71.         /* Wait for the workbench startup, if any */
  72.         proc=(struct Process *)FindTask(NULL);
  73.  
  74.         if (!(proc->pr_CLI)) {
  75.                 WaitPort(&(proc->pr_MsgPort));
  76.                 msg=(struct WBStartup *)GetMsg(&(proc->pr_MsgPort));
  77.         } else  msg=NULL;
  78.  
  79.         if (DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",37L)) {
  80.                 if (MMUBase=(struct MMUBase *)OpenLibrary("mmu.library",41L)) {
  81.  
  82.                         err=ERROR_REQUIRED_ARG_MISSING;
  83.  
  84.                         myrd=NULL;      /* reset the temporary ReadArgs */
  85.                         oldout=NULL;
  86.                         oldconsole=NULL;
  87.                         if (msg) {
  88.                                 oldout=SelectOutput(NULL);
  89.                                 oldconsole=SetConsoleTask(NULL);
  90.                                 rd=ReadTTArgs(msg,args,&myrd);
  91.                         } else  rd=ReadArgs(TEMPLATE,args,NULL);
  92.  
  93.                         if (rd) {
  94.                                 if (!GetMMUType()) {
  95.                                         Printf("MuFastChip requires a working MMU.\n");
  96.                                         err=10;
  97.                                 } else {
  98.  
  99.                                         err=0;
  100.  
  101.                                         if (args[OPT_ON] || (!args[OPT_OFF])) {
  102.                                                 err=EnableFastChip();
  103.                                         }
  104.  
  105.                                         if (args[OPT_OFF]) {
  106.                                                 err=DisableFastChip();
  107.                                         }
  108.                                 }
  109.  
  110.                                 FreeArgs(rd);
  111.                                 if (myrd) FreeDosObject(DOS_RDARGS,myrd);
  112.                                 if (msg)  Close(SelectOutput(NULL));
  113.                         } else  err=IoErr();
  114.  
  115.                         if (msg) {
  116.                                 SelectOutput(oldout);
  117.                                 SetConsoleTask(oldconsole);
  118.                         }
  119.  
  120.                         if (err<64) {
  121.                                 rc=err;
  122.                                 err=0;
  123.                         } else {
  124.                                 if (!msg) PrintFault(err,"MuFastChip failed");
  125.                                 rc=10;
  126.                         }
  127.                         SetIoErr(err);
  128.  
  129.                         CloseLibrary((struct Library *)MMUBase);
  130.                 } else if (!msg) PrintFault(ERROR_OBJECT_NOT_FOUND,"MuFastChip requires the mmu.library V41 or better");
  131.                 CloseLibrary((struct Library *)DOSBase);
  132.         }
  133.  
  134.         if (msg) {
  135.                 Forbid();
  136.                 ReplyMsg((struct Message *)msg);
  137.         }
  138.  
  139.         return rc;
  140. }
  141. ///
  142. /// ReadTTArgs
  143. struct RDArgs *ReadTTArgs(struct WBStartup *msg,LONG args[],struct RDArgs **tmp)
  144. {
  145. struct WBArg *wbarg;
  146. struct DiskObject *dop;
  147. char **tt;                      /* ToolTypes array */
  148. char *wbstr;                    /* Our self-made workbench argument string */
  149. char *here;
  150. BPTR oldlock;
  151. ULONG len;
  152. struct RDArgs *rd=NULL,*myrd=NULL;
  153. LONG err=0;
  154. BPTR newout;
  155.  
  156.         if (IconBase=OpenLibrary("icon.library",37L)) {
  157.                 if (wbarg=msg->sm_ArgList) {
  158.                         /* use a project icon if there is one... */
  159.                         if (msg->sm_NumArgs > 1) wbarg++;
  160.  
  161.                         /* go into the directory */
  162.                         oldlock=CurrentDir(wbarg->wa_Lock);
  163.  
  164.                         if (dop=GetDiskObject(wbarg->wa_Name)) {
  165.                                 if (tt=dop->do_ToolTypes) {
  166.                                         /* Read a special tool type for the output window */
  167.  
  168.                                         /* Calc the size of the argument string */
  169.  
  170.                                         len = 3;        /* reserve space for SPC,LF,NUL */
  171.                                         while (*tt) {
  172.                                                 len += strlen(*tt)+1;   /* string, plus space */
  173.                                                 tt++;
  174.                                         }
  175.  
  176.                                         if (wbstr=AllocVec(len,MEMF_PUBLIC)) {
  177.                                                 /* Now copy the arguments into this string, one by one
  178.                                                    and check whether the argument string is still valid. */
  179.  
  180.                                                 tt=dop->do_ToolTypes;
  181.                                                 here=wbstr;
  182.                                                 do{
  183.                                                         *here='\0';                     /* terminate string */
  184.                                                         /* Check whether this tool type is
  185.                                                            commented out. Just ignore it in this case */
  186.                                                         if (*tt) {
  187.                                                                 if (**tt=='(' || **tt==';')
  188.                                                                         continue;
  189.  
  190.                                                                 strcpy(here,*tt);      /* Add TT string */
  191.                                                         }
  192.                                                         len=strlen(here);
  193.                                                         here[len]='\n';
  194.                                                         here[len+1]='\0';               /* terminate string */
  195.  
  196.                                                         /* Now try to ReadArg' this string */
  197.  
  198.                                                         /* release old arguments left over from last loop */
  199.                                                         if (rd) FreeArgs(rd);
  200.                                                         if (myrd) FreeDosObject(DOS_RDARGS,myrd);
  201.                                                         rd=NULL;
  202.                                                         memset(args,0,sizeof(LONG)*OPT_COUNT);
  203.  
  204.                                                         if (myrd=AllocDosObject(DOS_RDARGS,NULL)) {
  205.                                                                 /* Allocate and setup the ReadArgs source */
  206.